﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using t01crm.Data;

namespace t01crm.Business
{
    public class ListingCollection : ObservableCollection<Listing>
    {
        public ListingCollection(IEnumerable<Listing> listing) :
            base(listing)
        {
            this.Neighborhoods = new ObservableCollection<Neighborhood>();
            this.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(ListingCollection_CollectionChanged);
        }

        public ListingCollection()
        {
            this.Neighborhoods = new ObservableCollection<Neighborhood>();
            this.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(ListingCollection_CollectionChanged);
        }

        void ListingCollection_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            if (e.NewItems != null)
            {
                foreach (Listing listing in e.NewItems)
                {
                    //  listing.ParentListingCollection = this;
                }
            }
        }

        public ObservableCollection<Neighborhood> Neighborhoods { get; set; }

        internal Neighborhood GetNeighborhoodById(int id)
        {
            foreach (Neighborhood n in Neighborhoods)
            {
                if (id == n.Id) return n;
            }
            return null;
        }
    }
}
